<!--
 * @description  : 市管检查-备忘录组件
 * @descriptionDetail: 市管检查-备忘录组件
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2022-07-09 18:43:02
-->
<template>
  <view>
    <theme-navbar
      :is-white="false"
      title="备忘录"
      :customBack="handlerBack"
      style="z-index: 99999"
    >
      <view class="nav-right-icon" v-if="!isDisabled" @tap="handlerSure">
        确定
      </view>
    </theme-navbar>
    <view v-for="(item, idx) in records" :key="idx">
      <!-- 开关选择 -->
      <u-cell-item :title="item.itemName" :arrow="false" class="cell" :title-style="mainLabelStyle" v-if="item.operateType == '91401'">
        <u-switch slot="right-icon" v-model="checkObj[item.checkKey]" @change="handlerSwitch"></u-switch>
      </u-cell-item>
      <!-- 选择框 -->
      <u-cell-item :title="item.itemName" class="cell" :title-style="mainLabelStyle" v-if="item.operateType == '91402'">
        <u-input input-align="right" :custom-style="pointerStyle" :disabled="true" placeholder="请选择" slot="right-icon" v-model="checkObj[item.checkKey]" @tap="handlerSelShow(item)" />
      </u-cell-item>
      <!-- 输入框 -->
      <u-cell-item :title="item.itemName" :arrow="false" class="cell" :title-style="mainLabelStyle" v-if="item.operateType == '91403'">
        <u-input input-align="right" :disabled="isDisabled" slot="right-icon" v-model="checkObj[item.checkKey]" />
      </u-cell-item>
      <u-field
        type="textarea"
        placeholder="请输入"
        :label="item.itemName"
        label-width="80"
        style="height: 300px;"
        :disabled="isDisabled"
        v-if="item.operateType == '91404'"
        v-model="checkObj[item.checkKey]"
      >
      </u-field>
    </view>
  </view>
</template>
<script>
export default {
  name: "MemoCom",
  props: {
    menuData: {
      type: Object,
      default: () => {},
    },
    recordDatas: {
      type: Array,
      default: () => [],
    },
    isDisabled: {   // 是否可编辑
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      records: this.recordDatas,
      checkObj: {},
      dealMap: {},
      preFix: 'L',  // 指标前缀
      mainLabelStyle: {
        // 'color': '#000',
        // 'fontWeight': '600',
      },
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-25 fsx start
			pointerStyle: {
			  marginRight: "5px",
				pointerEvents: "none !important"
			},
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-25 fsx start
    }
  },
  watch: {
    menuData(v) {
      console.log("监听", v);
    },
  },
  created () {
    console.log("数据", this.menuData);
    let dicts = this.$store.state.dicts['M_CHECK_HANDLE_RESULT_ZJ'];
    dicts.forEach(d => this.dealMap[d.bcbCode] = d.bcbName);
    this.records.forEach(r => {
      r.checkKey = this.preFix + r.itemUuid;
      this.$set(this.checkObj, r.checkKey, r.checkData || (r.operateType == '91401' ? r.defaultValue == 'true' : ''));
      // 子项
      r.nextRecords && r.nextRecords.forEach(nr => {
        nr.checkKey = this.preFix + nr.itemUuid;
        this.$set(this.checkObj, nr.checkKey, nr.checkData || (nr.operateType == '91401' ? nr.defaultValue == 'true' : ''));
      });
      // 处理方式
      if (r.jgsxDealUuidZj) {
        r.dealList = [];
        r.jgsxDealUuidZj.split(",").forEach(j => r.dealList.push({label: this.dealMap[j], value: j, itemUuid: r.itemUuid,}));
      }
    });
  },
  methods: {
    // 确定
    handlerSure() {
      // 处理数据
      Object.keys(this.checkObj).forEach(k => this.recursive(this.records, k));
      this.$emit("ok", {records: this.records, comType: this.menuData.type,});
    },
    // 递归赋值选中项
    recursive(arr, ck) {
      arr.forEach(item => {
        if (item.itemUuid == ck.replace(this.preFix, "")) {
          item.checkData = this.checkObj[ck];
        } else {
          if (item.nextRecords) {
            this.recursive(item.nextRecords, ck)
          }
        }
      })
    },
    // 关闭
    handlerBack() {
      this.$emit("close", true);
    },
  },
}
</script>
<style lang="scss" scoped>
@import "@/style/common/rightMenu.scss";
</style>